﻿CREATE FUNCTION [dbo].[MonthsApart_](
  @FromDate DATETIME,
  @ToDate DATETIME
)
RETURNS INT WITH SCHEMABINDING
AS
BEGIN
        RETURN  CASE
                       WHEN DATEPART(day, @FromDate) > DATEPART(day, @ToDate) THEN DATEDIFF(month, @FromDate, @ToDate) - 1
                       ELSE DATEDIFF(month, @FromDate, @ToDate)
               END
END

